import React, {useRef} from "react";
import Qs from 'qs'
import axios from "../../../../http";
import {CheckList, NavBar} from "antd-mobile";
//import {SearchBar} from "@ant-design/react-native";
//import { SearchBarRef } from 'antd-mobile/es/components/search-bar'
import {withRouter} from "react-router";
import {PRIVATE_ROUTE} from "../../../../route.constants";
class UserCheckBoxList extends React.Component {


    constructor(props) {

        super(props);

        this.state={userList:[],hasMore:true};

    }
    //searchRef = useRef<SearchBarRef>(null)

    loadUserData=()=>{
        axios.post('api/core/access/user/findAllExceptLoginUser', Qs.stringify({
        }),{headers: {'Content-Type': 'application/x-www-form-urlencoded'}})
            .then((response)=>{
                let  dataList=response.data.data;
                let userList=new Array()
                for(let i=0;i<dataList.length;i++){
                    let user=dataList[i];
                    userList.push(user);
                }
                this.setState({userList:userList});
                if(this.props.location.state!=undefined){
                    this.setState(this.props.location.state);
                }
            })
            .catch(function (error) {

            });

    }
    onChange=(val: string[])=>{
        this.setState({userViewList:val})
    }
    componentDidMount() {
            this.loadUserData()
    }

    render(){
        return(
            <>

                <NavBar onBack={()=>{
                    if(this.state.id!=undefined){
                        this.props.history.push({ pathname: "/main/"+PRIVATE_ROUTE.APP_OA_WORK_SCHEDULE_EDIT, state: this.state });
                    }else{
                        this.props.history.push({ pathname: "/main/"+PRIVATE_ROUTE.APP_OA_WORK_SCHEDULE_ADD, state: this.state });
                    }
                }}>请选择用户</NavBar>

                <CheckList multiple defaultValue={this.state.userViewList} onChange={this.onChange} >

                    {this.state.userList.map((item, index) => (
                        <CheckList.Item value={item.realName+'_'+item.id}>{item.name+'('+item.realName+')'}</CheckList.Item>
                    ))}

                </CheckList>


            </>


        )


    }
}

export default withRouter(UserCheckBoxList)